package com.fruit.service;

import com.fruit.service.thread.OrderStatusThread;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Service
@Slf4j
public class ThreadPoolService {

    /** 短信服务主线程 */
    @Autowired
    private OrderStatusThread orderStatusThread;

    /**
     * 方法描述: 程序初始化时启动发送短信线程 <br>
     * 版本: 1.0 <br>
     * 作者: xiewei <br>
     * @since 2021/4/1 13:50 <br>
     */
    @PostConstruct
    public void init() {
        try {
            this.orderStatusThread.start();
            log.info("物流线程启动");
        } catch (Exception e) {
            log.error("物流线程启动失败,{}",e);
        }
    }

    /**
     * 方法描述: 程序退出 <br>
     * 版本: 1.0 <br>
     * 作者: xiewei <br>
     * @since 2021/4/1 11:57 <br>
     */
    @PreDestroy
    public void destroy() {
        this.orderStatusThread.interrupt();
        log.info("后台线程关闭");
    }
}